package test.reflect;

import java.lang.reflect.Method;

import net.sf.cglib.proxy.Enhancer;
import net.sf.cglib.proxy.MethodInterceptor;
import net.sf.cglib.proxy.MethodProxy;

public class MyProxy implements MethodInterceptor{
	private Enhancer enhancer = new Enhancer();
	public Object getProxy(Class<Test> clazz){
		enhancer.setSuperclass(clazz);
		enhancer.setCallback(this);
		return enhancer.create();
	}
	public Object intercept(Object obj, Method method, Object[] args, MethodProxy proxy) throws Throwable {
		System.out.println(obj.getClass().getName()+"."+method.getName()+"()");
		Object result = proxy.invokeSuper(obj, args);
		return result;
	}
	public static void main(String args[]){
		MyProxy mp = new MyProxy();
		Test t = (Test)mp.getProxy(Test.class);
		t.print();
	}
	
}
class Test{
	private String str="fuck";
	public Test(){
	}
	public Test(String str){
		this.str = str;
	}
	public void print(){
		System.out.println(this.str);
	}
}